package com.cn.boot.sample.business.controller;

import com.anji.captcha.model.common.ResponseModel;
import com.anji.captcha.model.vo.CaptchaVO;
import com.anji.captcha.service.CaptchaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * aj-captcha
 * 验证码-登录接口二次校验验证码测试
 *
 * @author Chen Nan
 */
@Slf4j
@RestController
@RequestMapping("/auth")
@Api(tags = "测试21-验证码登录", produces = MediaType.APPLICATION_JSON_VALUE)
public class LoginController {

    @Autowired
    private CaptchaService captchaService;

    /**
     * @param captchaVerification 前端根据check接口返回的token以及用户point移动信息aesEncrypt
     *                            AES加密密钥为get接口返回的secretKey
     *                            前端计算此参数代码见verify.js 333行
     */
    @PostMapping("/login")
    @ApiOperation("后端二次校验接口示例")
    public ResponseModel get(@RequestParam("captchaVerification") String captchaVerification) {
        CaptchaVO captchaVO = new CaptchaVO();
        captchaVO.setCaptchaVerification(captchaVerification);
        ResponseModel response = captchaService.verification(captchaVO);
        if (response.isSuccess() == false) {
            //验证码校验失败，返回信息告诉前端
            //repCode  0000  无异常，代表成功
            //repCode  9999  服务器内部异常
            //repCode  0011  参数不能为空
            //repCode  6110  验证码已失效，请重新获取
            //repCode  6111  验证失败
            //repCode  6112  获取验证码失败,请联系管理员
        }
        return response;
    }

}
